ARG IMAGE

FROM $IMAGE

RUN sed -e 's|^mirrorlist=|#mirrorlist=|g' \
    -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirror.nju.edu.cn|g' \
    -i /etc/yum.repos.d/CentOS-*.repo \
 && yum install -y epel-release \
 && sed -e 's!^metalink=!#metalink=!g' \
    -e 's!^#baseurl=!baseurl=!g' \
    -e 's!//download\.fedoraproject\.org/pub!//mirror.nju.edu.cn!g' \
    -e 's!//download\.example/pub!//mirror.nju.edu.cn!g' \
    -e 's!http://mirrors!https://mirrors!g' \
    -i /etc/yum.repos.d/epel*.repo 

RUN yum -y install --setopt=tsflags=nodocs openssl-devel wget \
 && yum -y install --setopt=tsflags=nodocs gcc rpm-build rpm-devel rpmlint make coreutils diffutils patch rpmdevtools \
 && yum -y install --setopt=tsflags=nodocs autoconf automake pkgconfig \
 && yum -y install --setopt=tsflags=nodocs systemd-units

ADD keepalived.spec /keepalived.spec

ARG VERSION
ENV VERSION=$VERSION

RUN rpmdev-setuptree \
 && wget --no-check-certificate https://www.keepalived.org/software/keepalived-${VERSION}.tar.gz -O ~/rpmbuild/SOURCES/keepalived-${VERSION}.tar.gz \
 && cp /keepalived.spec ~/rpmbuild/SPECS/keepalived.spec \
 && sed -i "s#2.2.7#${VERSION}#g" ~/rpmbuild/SPECS/keepalived.spec

WORKDIR /root/rpmbuild/RPMS/x86_64
